1. Using modelflow with World Bank models#

The Modelflow python package has been developed to solve a wide range of models, see the modelflow github web site for working examples of the Solow Model, the FR/USB model and others.

The package has been substantially expanded to include special features that enable it to work with World Bank models originally developed in EViews and designed to use EViews Model Object for simuation.

This chapter illustrates how to access these models, how to load them into a modelflow anaconda environment on your computer and how to perform a variety of simulations

1.1. Accessing a world bank model#

At this time several World bank macrostructural models are available to download and use with modelflow. These include a macrostructural model for:

  • Indonesia

  • Nepal

  • Croatia

  • Iraq

  • Kenya

  • Bolivia

Each of these models has been developed as part of the outreach work of the World Bank. The basic modelling framework of each of these models is outlined in Burns et al. [2019] with specific extensions reflecting features of the individual country modelled.

This book uses as an example a climate aware model for Pakistan developed in 2020 and described in Burns et al. [2021] .

The World Bank models are distributed in the pcim file format of the modelflow and can be downloaded by right clicking on the links above. The Pakistan model can be downloaded here by right clicking on the above link and selecting Save Link as and placing the file on a directory accessible by your modelflow installation.

from worldbankMFModModels import pak

1.2. Preparing your python environment#

As always, the modelflow and other python packages that will be used need to be imported into your python session. The examples here and this book were written and solved in a Jupyter Notebook. There are some Jupyter specific commands included in these examples and these are annotated. However, the bulk of the content of the programs can be run in other environments, including Interactive Development Environments (IDE) like Spyderor MS Visual Code. All the programs have been tested under spyder as well as Jupyter Notebook.

It is assumed that:

  1. you have already installed modelflow and its various support packages following the instructions in Chapter xx

  2. you are using Anaconda, and that

  3. you have activated your modelflow environment by executing the following command from your python command line:

conda activate modelflow

where modelflow is the name you have given to the conda environment into which you installed modelflow.

# import the model class from modelflow package
from modelclass import model 
import modelmf       # Add useful features to pandas dataframes 
                     # using utlities initially developed for modelflow

   

model.widescreen()   # These modelflow commands ensure that outputs from modelflow play well with Jupyter Notebook
model.scroll_off()

Ib : next text has been split out and hidden in JB in the metadata

1.3. Working with PakMod under modelflow#

The basic method for working with any model is the same. Indeed the initial steps followed here are the same as were followed during the simple model discussion.

Process:

  1. Prepare the workspace

  2. Load the model Modelflow

  3. Design some scenarios

  4. Simulate the model

  5. Visualize the results

1.3.1. Load a pre-existing model, data and descriptions#

Ib : some changes

To load a model use the model.modelload() method of modelflow.

The command below

mpak,bline = model.modelload('C:\mflow\modelflow-manual\papers\mfbook\content\models\pak.pcim', alfa=0.7,run=1,keep= 'Baseline')

instantiates (creates an instance of) a modelflow model object and assigns it to the variable name mpak. The run=1 option executes the model and assigns the result of the model execution to the dataframe bline. The model is solved with the parameter alfa set to 0.7. The \(alfa \in (0,1)\) parameter determines the step size of the solution engine. The larger alfa the larger the step size. Larger step sizes may solve faster, but may have trouble finding a unique solution. Smaller step sizes take longer to solve but are more likely to find a unique solution. Values of alfa=.7 work well for World Bank models.

The keep option instructs modelflow to maintain in the model object (mpak) the results of the intitial scenario, assigning it the text name Baseline.

Ib : As it is now mpak will first look in the location specified, then it will look in the Global model repo.

#Replace the path below with the location of the pak.pcim file on your computer
mpak,bline = model.modelload('C:\mflow\modelflow-manual\papers\mfbook\content\models\pak.pcim',
                                alfa=0.7,run=1,keep= 'Baseline')
Open file from URL:  https://raw.githubusercontent.com/IbHansen/modelflow-manual/main/model_repo/pak.pcim

Note

the variable bline contains the dataframe with the results of the simulation. This is distinct from the data that is stored by the kept= command. That said, the data associated with each, while stored separately, have the same numerical values. The keep option is described in more detail toward the end of this section.

Box [^BoxWBMnemonics]: World Bank Mnemonics

A typical World Bank model will have in excess of 300 variables. Each has a mnemonic that is structured in a specific way, The root for almost all are 14 characters long (some special variables have additional characters appended to this root) (see discussion in section).

\[\texttt{12345678901234}\]
\[\color{green}{\texttt{CCC}}\color{red}{\texttt{AA}}\color{lime}{\texttt{MMM}}\color{blue}{\texttt{NNNN}}\color{magenta}{\texttt{U}}\color{black}{\texttt{C}}\]

where:

Letters

Meaning

\(\color{green}{\texttt{CCC}}\)

The three-leter ISO code for a country – i.e. IDN for Indonesia, RUS for Russia

\(\color{red}{\texttt{AA}}\)

The two-letter major accounting system to which the variable attaches,

\(\color{lime}{\texttt{MMM}}\)

The three-letter major sub-category of the data - i.e. GDP, EXP - expenditure

\(\color{blue}{\texttt{NNNN}}\)

The four-letter minor sub-category MKTP for market prices

\(\color{magenta}{\texttt{U}}\)

The measure (K: real variable;C: Current Values; X: Prices)

\(\color{black}{\texttt{C}}\)

denotes the Currency (N: National currency; D: USD; P: PPP)

Common major accounting systems mnemonics: the, \(\color{red}{\texttt{AA}}\)s from above:

Code

Meaning

NY

National income

NE

National expenditure Accounts

NV

Value added accounts

GG

General Government Accounts

BX

Balance of Payments: Exports

BM

Balance of Payments: Imports

BN

Balance of Payments: Net

BF

Balance of Payments: Financial Account

Thus

Mnemonic

Meaning

IDNNYGDPMKTPKN

Indonesia GDP at market prices, real in Indonesian Rupiah

KENNECPNPRVTXN

Kenya Private (household) consumption expenditure schillings deflator

BOLGGEXPGNFSCN

Bolivia Government Expenditure on Goods and services (GNFS) in current Bolivars

HRVGGREVDCITCN

Croatia Government Revenues Direct Corporate Income Taxes in current Euros

NPLBXGSRNFSVCD

Nepal BOP Exports of non-factor services (goods and services) in current USD

mpak.PAKNECONPRVTKN
Endogeneous: PAKNECONPRVTKN: Household Consumption
Formular: FRML <Z,EXO> PAKNECONPRVTKN = (PAKNECONPRVTKN(-1)*EXP(-PAKNECONPRVTKN_A+ (-0.2*(LOG(PAKNECONPRVTKN(-1))-LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1)))+1*((LOG((PAKNYYWBTOTLCN*(1-PAKGGREVDRCTXN/100))/PAKNECONPRVTXN))-(LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1))))+0.0303228629698929+0.0163839011059956*DURING_2010-0.3*(PAKFMLBLPOLYXN/100-((LOG(PAKNECONPRVTXN))-(LOG(PAKNECONPRVTXN(-1)))))) )) * (1-PAKNECONPRVTKN_D)+ PAKNECONPRVTKN_X*PAKNECONPRVTKN_D  $

PAKNECONPRVTKN  : Household Consumption
DURING_2010     : 
PAKFMLBLPOLYXN  : Policy Rate
PAKGGREVDRCTXN  : Effective tax rates
PAKNECONPRVTKN_A: Add factor:Household Consumption
PAKNECONPRVTKN_D: Exo dummy:Household Consumption
PAKNECONPRVTKN_X: Exo value:Household Consumption
PAKNECONPRVTXN  : Household demand
PAKNYYWBTOTLCN  : Economy-wide wage bill

Values :
  2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
Base 23,323,036.25 23,831,715.85 24,394,056.99 25,012,863.14 25,644,576.47 26,265,983.02 26,879,437.91 27,498,434.77 28,135,788.13 28,799,212.78 29,491,571.76 30,212,660.19 30,960,907.45 31,734,538.54 32,532,219.14 33,353,302.83 34,197,805.48 35,066,228.74 35,959,330.18 36,877,923.76 37,822,748.20 38,794,408.68 39,793,374.80 40,820,010.54 41,874,615.17 42,957,461.68 44,068,827.23 45,209,015.11 46,378,370.00 47,577,288.77 48,806,228.33 50,065,711.31 51,356,329.99 52,678,748.39 54,033,702.57 55,421,999.62 56,844,515.55 58,302,192.02 59,796,034.87 61,327,109.19 62,896,537.24 64,505,496.38 66,155,217.34 67,846,982.74 69,582,126.19 71,362,031.74 73,188,133.85 75,061,917.56 76,984,918.97 78,958,726.15 80,984,979.29 83,065,374.35 85,201,661.59 87,395,647.94 89,649,199.01 91,964,240.90 94,342,761.78 96,786,813.89 99,298,515.39 101,880,052.48 104,533,681.48 107,261,730.11 110,066,602.86 112,950,779.34 115,916,817.98 118,967,358.87 122,105,126.03 125,332,929.77 128,653,669.14 132,070,334.53 135,586,010.26 139,203,876.19 142,927,214.45 146,759,407.28 150,703,941.70 154,764,412.98 158,944,527.70 163,248,106.38 167,679,086.79 172,241,527.17 176,939,609.49
Last 23,323,036.25 23,831,715.85 24,394,056.99 25,012,863.14 25,644,576.47 26,265,983.02 26,879,437.91 27,498,434.77 28,135,788.13 28,799,212.78 29,491,571.76 30,212,660.19 30,960,907.45 31,734,538.54 32,532,219.14 33,353,302.83 34,197,805.48 35,066,228.74 35,959,330.18 36,877,923.76 37,822,748.20 38,794,408.68 39,793,374.80 40,820,010.54 41,874,615.17 42,957,461.68 44,068,827.23 45,209,015.11 46,378,370.00 47,577,288.77 48,806,228.33 50,065,711.31 51,356,329.99 52,678,748.39 54,033,702.57 55,421,999.62 56,844,515.55 58,302,192.02 59,796,034.87 61,327,109.19 62,896,537.24 64,505,496.38 66,155,217.34 67,846,982.74 69,582,126.19 71,362,031.74 73,188,133.85 75,061,917.56 76,984,918.97 78,958,726.15 80,984,979.29 83,065,374.35 85,201,661.59 87,395,647.94 89,649,199.01 91,964,240.90 94,342,761.78 96,786,813.89 99,298,515.39 101,880,052.48 104,533,681.48 107,261,730.11 110,066,602.86 112,950,779.34 115,916,817.98 118,967,358.87 122,105,126.03 125,332,929.77 128,653,669.14 132,070,334.53 135,586,010.26 139,203,876.19 142,927,214.45 146,759,407.28 150,703,941.70 154,764,412.98 158,944,527.70 163,248,106.38 167,679,086.79 172,241,527.17 176,939,609.49
Diff 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Input last run:
  2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100
DURING_2010 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
PAKFMLBLPOLYXN 6.79 7.14 7.40 7.57 7.65 7.65 7.58 7.43 7.24 7.00 6.74 6.47 6.20 5.94 5.70 5.48 5.28 5.10 4.95 4.82 4.70 4.61 4.53 4.46 4.41 4.37 4.33 4.30 4.28 4.26 4.24 4.23 4.22 4.21 4.20 4.19 4.18 4.17 4.16 4.15 4.14 4.13 4.12 4.11 4.09 4.08 4.07 4.06 4.05 4.04 4.03 4.02 4.01 4.00 3.99 3.98 3.98 3.97 3.96 3.96 3.95 3.95 3.94 3.94 3.94 3.94 3.94 3.94 3.94 3.94 3.94 3.95 3.95 3.96 3.96 3.97 3.98 3.99 4.00 4.01 4.03
PAKGGREVDRCTXN 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22
PAKGGREVDRCTXN(-1) 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22 4.22
PAKNECONPRVTKN(-1) 22,703,537.11 23,323,036.25 23,831,715.85 24,394,056.99 25,012,863.14 25,644,576.47 26,265,983.02 26,879,437.91 27,498,434.77 28,135,788.13 28,799,212.78 29,491,571.76 30,212,660.19 30,960,907.45 31,734,538.54 32,532,219.14 33,353,302.83 34,197,805.48 35,066,228.74 35,959,330.18 36,877,923.76 37,822,748.20 38,794,408.68 39,793,374.80 40,820,010.54 41,874,615.17 42,957,461.68 44,068,827.23 45,209,015.11 46,378,370.00 47,577,288.77 48,806,228.33 50,065,711.31 51,356,329.99 52,678,748.39 54,033,702.57 55,421,999.62 56,844,515.55 58,302,192.02 59,796,034.87 61,327,109.19 62,896,537.24 64,505,496.38 66,155,217.34 67,846,982.74 69,582,126.19 71,362,031.74 73,188,133.85 75,061,917.56 76,984,918.97 78,958,726.15 80,984,979.29 83,065,374.35 85,201,661.59 87,395,647.94 89,649,199.01 91,964,240.90 94,342,761.78 96,786,813.89 99,298,515.39 101,880,052.48 104,533,681.48 107,261,730.11 110,066,602.86 112,950,779.34 115,916,817.98 118,967,358.87 122,105,126.03 125,332,929.77 128,653,669.14 132,070,334.53 135,586,010.26 139,203,876.19 142,927,214.45 146,759,407.28 150,703,941.70 154,764,412.98 158,944,527.70 163,248,106.38 167,679,086.79 172,241,527.17
PAKNECONPRVTKN_A -0.02 -0.02 -0.02 -0.01 -0.01 -0.01 -0.01 -0.01 -0.01 -0.01 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00 -0.00
PAKNECONPRVTKN_D 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
PAKNECONPRVTKN_X 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
PAKNECONPRVTXN 1.68 1.85 2.01 2.18 2.34 2.50 2.65 2.80 2.93 3.06 3.18 3.29 3.39 3.49 3.58 3.68 3.77 3.87 3.97 4.07 4.17 4.27 4.38 4.50 4.61 4.73 4.86 4.99 5.12 5.25 5.39 5.54 5.68 5.83 5.99 6.15 6.31 6.48 6.65 6.82 7.00 7.18 7.37 7.56 7.75 7.95 8.16 8.36 8.58 8.80 9.02 9.25 9.48 9.72 9.97 10.22 10.48 10.74 11.02 11.29 11.58 11.87 12.17 12.48 12.80 13.12 13.45 13.80 14.15 14.51 14.88 15.27 15.66 16.07 16.48 16.91 17.35 17.81 18.28 18.76 19.26
PAKNECONPRVTXN(-1) 1.53 1.68 1.85 2.01 2.18 2.34 2.50 2.65 2.80 2.93 3.06 3.18 3.29 3.39 3.49 3.58 3.68 3.77 3.87 3.97 4.07 4.17 4.27 4.38 4.50 4.61 4.73 4.86 4.99 5.12 5.25 5.39 5.54 5.68 5.83 5.99 6.15 6.31 6.48 6.65 6.82 7.00 7.18 7.37 7.56 7.75 7.95 8.16 8.36 8.58 8.80 9.02 9.25 9.48 9.72 9.97 10.22 10.48 10.74 11.02 11.29 11.58 11.87 12.17 12.48 12.80 13.12 13.45 13.80 14.15 14.51 14.88 15.27 15.66 16.07 16.48 16.91 17.35 17.81 18.28 18.76
PAKNYYWBTOTLCN 31,668,962.10 35,318,535.81 39,478,723.69 44,122,274.60 49,131,064.19 54,388,458.83 59,811,621.32 65,348,151.24 70,963,951.38 76,635,715.09 82,349,107.81 88,099,517.69 93,892,794.20 99,744,992.98 105,681,173.83 111,733,564.77 117,939,429.95 124,338,953.88 130,973,348.56 137,883,374.08 145,108,334.85 152,685,530.22 160,650,076.28 169,034,989.35 177,871,430.97 187,189,036.41 197,016,277.80 207,380,834.30 218,309,956.52 229,830,819.22 241,970,859.14 254,758,095.98 268,221,434.60 282,390,946.77 297,298,132.11 312,976,159.17 329,460,088.63 346,787,076.25 364,996,582.21 384,130,541.92 404,233,549.97 425,353,038.35 447,539,453.82 470,846,436.68 495,331,005.29 521,053,747.74 548,079,024.08 576,475,180.59 606,314,777.52 637,674,835.52 670,637,087.67 705,288,293.72 741,720,515.29 780,031,453.80 820,324,810.33 862,710,670.38 907,305,916.16 954,234,673.78 1,003,628,792.64 1,055,628,361.87 1,110,382,265.24 1,168,048,761.19 1,228,796,172.87 1,292,803,519.39 1,360,261,266.11 1,431,372,117.34 1,506,351,858.31 1,585,430,256.27 1,668,852,025.50 1,756,877,860.83 1,849,785,542.44 1,947,871,092.19 2,051,450,122.96 2,160,859,101.06 2,276,456,820.16 2,398,625,956.82 2,527,774,729.09 2,664,338,661.76 2,808,782,485.21 2,961,602,164.05 3,123,327,068.01
PAKNYYWBTOTLCN(-1) 28,368,951.83 31,668,962.10 35,318,535.81 39,478,723.69 44,122,274.60 49,131,064.19 54,388,458.83 59,811,621.32 65,348,151.24 70,963,951.38 76,635,715.09 82,349,107.81 88,099,517.69 93,892,794.20 99,744,992.98 105,681,173.83 111,733,564.77 117,939,429.95 124,338,953.88 130,973,348.56 137,883,374.08 145,108,334.85 152,685,530.22 160,650,076.28 169,034,989.35 177,871,430.97 187,189,036.41 197,016,277.80 207,380,834.30 218,309,956.52 229,830,819.22 241,970,859.14 254,758,095.98 268,221,434.60 282,390,946.77 297,298,132.11 312,976,159.17 329,460,088.63 346,787,076.25 364,996,582.21 384,130,541.92 404,233,549.97 425,353,038.35 447,539,453.82 470,846,436.68 495,331,005.29 521,053,747.74 548,079,024.08 576,475,180.59 606,314,777.52 637,674,835.52 670,637,087.67 705,288,293.72 741,720,515.29 780,031,453.80 820,324,810.33 862,710,670.38 907,305,916.16 954,234,673.78 1,003,628,792.64 1,055,628,361.87 1,110,382,265.24 1,168,048,761.19 1,228,796,172.87 1,292,803,519.39 1,360,261,266.11 1,431,372,117.34 1,506,351,858.31 1,585,430,256.27 1,668,852,025.50 1,756,877,860.83 1,849,785,542.44 1,947,871,092.19 2,051,450,122.96 2,160,859,101.06 2,276,456,820.16 2,398,625,956.82 2,527,774,729.09 2,664,338,661.76 2,808,782,485.21 2,961,602,164.05

1.3.2. Extracting information about the model#

The newly loaded python object mpak is an instance of the model class and as such inherits the methods (functions) and properties (data) of that class. To learn about the model there are a variety of information methods that can be used to extract information about the model and its data.

Information about a specific variable

Method

Example

Information returned

.<variable name>

modelname['PAKNECONPRVTXN'].des

Dictionary of mnemonics and their variable descriptions

.desc

modelname['PAKNECONPRVTXN'].desc

List of variable description alone

Note

Wildcards The * character in the command mpak['PAKNECON*XN'].names is a wildcard character and the extopression will return all variables that begin PAKNECON and end XN. the ? is another wildcard expression. It will match only single characters. Thus mpak['PAKNECONPRVT?N'].names would return three variables: PAKNECONPRVTKN, PAKNECONPRVTXN, and PAKNECONPRVTXN. The real, current value, and deflators for household consumption expenditure.

Information about a number of variables that meet certain search criteria

The above functions can be used in conjunction with a wildcard specification to extract the same information about a number of variables that meet the criteria. To extract a list of all variables matching a pattern, we can use same methods.

Wildcards

The * operator matches multiple characters, the ? operator matches just one character

Method

Example

Information returned

.des

modelname.['*partialname*'].des

Returns Dictionary of all mnemonic and variable descriptions whose mnemonic matches

.desc

modelname.['*partialname'].desc

Returns list of variable descriptions whose mnemonic matches

.names

modelname.['*partialname'].names

Returns list of variable mnemonics that match

The ! operator If a wildcard is preceded by an exclamation mark ! the search will be done over the description of variables instead of the mnemonic

Method

Example

Information returned

.des

modelname.['!*GDP\*'].des

Returns Dictionary of all mnemonic and variable descriptions whose description contains the string GDP

.desc

modelname.['!*Consumption*'].desc

Returns list of variable descriptions whose description contains the string Consumption

.names

modelname.['!*Agriculture*'].names

Returns list of variable mnemonics whose description contains the string Agriculture

#Operator The # operator passes a predefined list to the search function and returns variable info about the variables in the list

Method

Example

Information returned

.des

modelname.['#MyList'].des

Returns Dictionary of all mnemonic and variable descriptions of the variables contained in the list MyList

.desc

modelname.['#MyList'].desc

Returns list of variable descriptions of variables contained in the list MyList

.names

modelname.['#MyList'].names

Returns list of variable mnemonics of variables contained in the list MyList

1.3.2.1. Some examples#

Return all variables that begin PAKNECON and end KN.

Ib : Changed XN to KN below so match with heading

mpak['PAKNECON*KN'].names
['PAKNECONENGYKN', 'PAKNECONGOVTKN', 'PAKNECONOTHRKN', 'PAKNECONPRVTKN']

Return a dictionary comprised of the mnemonics and the descriptions of all the variables that begin PAKNECONPRVT and end N, but have one character between the T and the N.

mpak['PAKNECONPRVT?N'].des
PAKNECONPRVTCN : Household demand
PAKNECONPRVTKN : Household Consumption
PAKNECONPRVTXN : Household demand

Return a list of the full description all the variables that have the word GDP in their description.

mpak['!*GDP*'].des
PAKNEHURAVERKN_       : Hurricane damage, percent of GDP
PAKNYGDPFCSTXN        : GDP at factor cost
PAKNYGDPFCSTXN_A      : Add factor:GDP at factor cost
PAKNYGDPFCSTXN_D      : Exo dummy:GDP at factor cost
PAKNYGDPFCSTXN_FITTED : Fitted  value:GDP at factor cost
PAKNYGDPFCSTXN_X      : Exo value:GDP at factor cost
PAKNYGDPGAP_          : Output Gap (% of Potential GDP)
PAKNYGDPMKTPCD        : Nominal GDP Market Prices (USD)
PAKNYGDPMKTPCN        : GDP, LCU
PAKNYGDPMKTPKN        : GDP Expenditure side at market prices
PAKNYGDPMKTPXN        : GDP deflator
PAKNYGDPPOTLKN        : Potential GDP

Ib : deleted it does not return a dict

Return a dictionary comprised of the variable name and description if all variables in a list.

Ib : Error in code reflection @lru_cache(maxsize=2048), removed and works in new version

Ib : deleted #Why does this not work? mylist=[‘PAKNECONPRVTKN’,’PAKNECONGOVTKN’,’PAKNEGDIFTOTKN’,’PAKNEEXPGNGSKN’,’PAKNEIMPGNFSKN’] mpak[mylist].des

Ib : It is a property

The property .var_description is a dictionary which contains the descriptor of the associated variable. As a dictionary you can not use wildcards. If there is no description to the variable the dictionary will return the variable name it was presented with.

mpak.var_description['PAKNYGDPMKTPKN']
'GDP Expenditure side at market prices'
mpak.var_description['A_VARIABLE']
'A_VARIABLE'

1.3.2.2. Equation information methods#

There are two functions to extract the equations from a model.

Command

Effect

mpak['PAKNECONPRVTKN'].frml

Returns a normalized version of the equation (the one actually used in modelflow)

mpak['PAKNECONPRVTKN'].eviews

In models imported from Eviews, reports the original eviews specification

The equation for consumption in mpak we see that it follows something very close to this formulation.

mpak.PAKNECONPRVTKN.frml
Endogeneous: PAKNECONPRVTKN: Household Consumption
Formular: FRML <Z,EXO> PAKNECONPRVTKN = (PAKNECONPRVTKN(-1)*EXP(-PAKNECONPRVTKN_A+ (-0.2*(LOG(PAKNECONPRVTKN(-1))-LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1)))+1*((LOG((PAKNYYWBTOTLCN*(1-PAKGGREVDRCTXN/100))/PAKNECONPRVTXN))-(LOG((PAKNYYWBTOTLCN(-1)*(1-PAKGGREVDRCTXN(-1)/100))/PAKNECONPRVTXN(-1))))+0.0303228629698929+0.0163839011059956*DURING_2010-0.3*(PAKFMLBLPOLYXN/100-((LOG(PAKNECONPRVTXN))-(LOG(PAKNECONPRVTXN(-1)))))) )) * (1-PAKNECONPRVTKN_D)+ PAKNECONPRVTKN_X*PAKNECONPRVTKN_D  $

PAKNECONPRVTKN  : Household Consumption
DURING_2010     : 
PAKFMLBLPOLYXN  : Policy Rate
PAKGGREVDRCTXN  : Effective tax rates
PAKNECONPRVTKN_A: Add factor:Household Consumption
PAKNECONPRVTKN_D: Exo dummy:Household Consumption
PAKNECONPRVTKN_X: Exo value:Household Consumption
PAKNECONPRVTXN  : Household demand
PAKNYYWBTOTLCN  : Economy-wide wage bill

The mpak['PAKNECONPRVTKN'].eviews command returns the equations before they were normalized. In most cases this is a slightly more legible form. Here following the EViews syntax, \(\Delta ln()\) is written as dlog().

mpak.PAKNECONPRVTKN.eviews
Not avaiable

1.4. Behavioural equations in the MFMod framework#

Recall a behavioural equation determines the value of an endogenous variable. For many of the variables in Wold Bank models, behavioural functions are estimated using an Error Correction Framework that splits the equation into a theoretically determined long run component and a more idiosyncratic short-run component.

Looking at the eviews representation of the consumption function:

DLOG(PAKNECONPRVTKN) =- 0.2*(LOG(PAKNECONPRVTKN( - 1)) - LOG(1.21203101101442) - LOG((((PAKBXFSTREMTCD( - 1) - PAKBMFSTREMTCD( - 1))*PAKPANUSATLS( - 1)) + PAKGGEXPTRNSCN( - 1) + PAKNYYWBTOTLCN( - 1)*(1 - PAKGGREVDRCTXN( - 1)/100))/PAKNECONPRVTXN( - 1))) + 0.763938860758873*DLOG((((PAKBXFSTREMTCD - PAKBMFSTREMTCD)*PAKPANUSATLS) + PAKGGEXPTRNSCN + PAKNYYWBTOTLCN*(1 - PAKGGREVDRCTXN/100))/PAKNECONPRVTXN) - 0.0634474791568939*@DURING("2009") - 0.3*(PAKFMLBLPOLYXN/100 - DLOG(PAKNECONPRVTXN))

Below the mnemonics are simplified to ease reading of the equation using:

Model Mnemonic

Simplified

Meaning

PAKNECONPRVTKN

\(CON^{KN}_t\)

Household Consumption

(PAKBXFSTREMTCD - PAKBMFSTREMTCD)*PAKPANUSATLS

\(Remit^{net}_t\)

Net remittances inflows in LCU

PAKGGEXPTRNSCN

\(TRANSF^{hhld}_t\)

Government transfers to households

DURING_2010

\(D^{2010}_t\)

A dummy

PAKFMLBLPOLYXN

\(r^{policy}_t\)

Policy Rate

PAKGGREVDRCTXN

\(DirectTxR_t\)

Direct Taxes: Effective rate

PAKNECONPRVTKN_A

\(CON^{KN_AF}_t\)

Add factor:Household Consumption

PAKNECONPRVTXN

\(CON^{XN}_t\)

Household Consumption Deflator

PAKNYYWBTOTLCN

\(WAGEBILL^{CN}_t\)

Economy-wide wage bill

\[\begin{align*} \Delta log(CON^{KN}_t) = &-0.2*\bigg[LOG(CON^{KN}_{t-1})-LOG\bigg({\frac{(Remit^{net}_{t-1}+WAGEBILL^{CN}_{t-1}+TRANSF^{hhld}_{t-1})*(1-DirectTxR_{t-1}/100)}{CON^{XN}_{t-1}}}\bigg)\bigg] \\ &+0.76*\Delta log \bigg({\frac{(Remit^{net}_{t}+WAGEBILL^{CN}_{t}+TRANSF^{hhld}_{t})*(1-DirectTxR_{t}/100)}{CON^{XN}_{t}}}\bigg) \\ &+0.030 + 0.016*D^{2010}_t-0.3*\bigg(r^{policy}_t/100-\Delta log(CON^{XN}_{t})\bigg) -CON^{KN_AF}_t \end{align*}\]

Where in this instance the short-run elasticity of consumption to disposable income is .76 , and the short run elasticity of consumption to the real interest rate is 0.3.

1.4.1. The ECM specification#

Pretty sure this repeats and earlier section. Delete one

The ECM approach used in World Bank models is described in [Wickens and Breusch, 1988], and addresses the above challenge by modelling both the long run relationship and the short run short run behaviour and brings them together into one equation.

The ECM specification is therefore a single equation comprised of two parts (the long run relationship, and the short-run relationship).

Consider as an example two variables say consumption and disposable income. Both have an underlying trend or in the parlance are co-integrated to degree 1. For simplicity we call them y an x.

1.4.1.1. The short run relationship#

In its simplest form we might have a short run relationship between the growth rates of our two variables such that:

\[\Delta log(Y_t) = \alpha + \beta \Delta log(X_t) +\epsilon_t\]

or substituting lower case letters for the logged values.

\[\Delta y_t = \alpha + \beta \Delta x_t +\epsilon_t\]

1.4.1.2. The long run equation#

The long run relates the level of the two (or more) variables. We can write a simple version of that equation as:

\[Y_t=αX_t^β+ \eta_t\]

Rewriting this (in logarithms) it can be expressed as:

\[y_t = ln⁡(α) + βy_t + \eta_t\]

1.4.2. The long run equation in the steady state#

First we note that in the steady state the expected value of the error term in the long run equation is zero (\(\eta_t=0 \)) so in those conditions we can simplify the long run relationship to:

\[y_t=ln⁡(α)+\beta x_t\]

or equivalently (substituting A for the log of \(\alpha\)).

\[y_t-A-βx_t=0\]

Moreover if we multiplied this by some arbitrary constant say \(-\lambda\) it would still equal zero.

\[-\lambda(y_t -A-βx_t)\]

and in the steady state this will also be true for the lagged variables

\[-\lambda(y_{t-1-} A - βx_{t-1})\]

1.5. Putting it together#

From before we have the short run equation:

\[\Delta y_t = \alpha + \beta \Delta x_t +\epsilon_t\]

Inserting the steady state expression into the short run equation makes no difference (in the long run) because in the long run it is equal to zero.

\[\Delta y_t = -\lambda(y_{t-1-}A-βx_{t-1}) + \alpha + \beta \Delta x_t +\epsilon_t\]

When the model is not in the steady state the expression \(y_{t-1}-A-βx_{t-1}\) is of course the error term from the long run equation (a measure of how far the dependent variable is from equilibrium).

1.5.1. Lambda, the speed of adjustment#

The parameter \(\lambda\) can be interpreted as the speed of adjustment. As long as \(\lambda\) is greater than zero and less or equal to one if there are no further disturbances ( \(\epsilon_t=0\)) the expression multiplied by lambda will slowly decline toward zero. How fast depends on how large or small is \(\lambda\).

To be convergent \(\lambda\) must be between 0 and 2, if its is negative or greater than one, then the long run portion of the equation will cause the disequilibrium to grow each period (\(\lambda\) >1) not diminish or if (\(\lambda\) >1<2) output will oscillate from positive to negative (\(\lambda <0\)).

Intuitively, the long run error term measures how far we are from equilibrium one period earlier (at t-1). The ECM term ensures that we will slowly converge to equilibrium – the point at which the long run equation holds exactly. If $\(\lambda\)\( is greater than zero but less than one (or equal to one) some portion of the previous period year's disequilibrium will be absorbed each year. How much is absorbed depends on the size of estimated speed of the adjustment coefficient \)\lambda$.

Looking at an ECM equation we can then break it up into its component parts. For the consumption function it will look something like this:

\[\Delta c_t = -\lambda (\underbrace{ log(C_{t-1})-log(Wages_{t-1}-Taxes_{t-1}+Transfers_{t-1} + \alpha)} _\text{Long run} +\beta \underbrace{\Delta y_t}_\text{short run}\]